/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.library.view.component;


import it.gmariotti.cardslib.library.ResourceTable;
import it.gmariotti.cardslib.library.view.base.CardViewInterface;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.StackLayout;
import ohos.app.Context;

/**
 * Compound View for Shadow Component.
 * </p>
 * It is built with base_shadow_layout xml file.
 * You can customize this component. See https://github.com/gabrielemariotti/cardslib/tree/master/SHADOW.md for more information.
 * </p>
 * You can customize it with your style files. Please see card.shadow_image style.
 * </p>
 * Also you can use a custom layout for Shadow Component in your xml layout.
 * <pre><code>
 *
 *
 * </code></pre>
 *
 * @author Gabriele Mariotti (gabri.mariotti@gmail.com)
 */
public class CardShadowView extends StackLayout implements CardViewInterface {

    //--------------------------------------------------------------------------
    // Custom Attrs
    //--------------------------------------------------------------------------

    /**
     * Default Layout for ShadowView
     */
    protected int card_shadow_layout_resourceID = ResourceTable.Layout_base_shadow_layout;

    /**
     * Global View for this Component
     */
    protected Component mInternalOuterView;

    //--------------------------------------------------------------------------
    // Constructors
    //--------------------------------------------------------------------------

    public CardShadowView(Context context) {
        super(context);
        init(null, "0");
    }

    public CardShadowView(Context context, AttrSet attrs) {
        super(context, attrs);
        init(attrs, "0");
    }

    public CardShadowView(Context context, AttrSet attrs, String defStyle) {
        super(context, attrs, defStyle);
        init(attrs, defStyle);
    }

    //--------------------------------------------------------------------------
    // Init
    //--------------------------------------------------------------------------

    /**
     * Initialize
     *
     * @param attrs
     * @param defStyle
     */
    protected void init(AttrSet attrs, String defStyle) {
        //Init attrs
        initAttrs(attrs, defStyle);

        //Init View
        //todo no such method
//      if (!isInEditMode())
            initView();
    }

    /**
     * Init custom attrs.
     *
     * @param attrs
     * @param defStyle
     */
    protected void initAttrs(AttrSet attrs, String defStyle) {
        if (attrs.getAttr("card_shadow_layout_resourceID").isPresent()) {
            card_shadow_layout_resourceID = attrs.getAttr("card_header_layout_resourceID").get().getIntegerValue();
        }
    }

    /**
     * Init view
     */
    protected void initView() {

        LayoutScatter inflater = LayoutScatter.getInstance(mContext);
        mInternalOuterView = inflater.parse(card_shadow_layout_resourceID, this, true);

    }

    //--------------------------------------------------------------------------
    // Getters and Setters
    //--------------------------------------------------------------------------

    @Override
    public Component getInternalOuterView() {
        return mInternalOuterView;
    }


}
